package com.ssm.Dao;

import com.ssm.Utils.DBCPUtils;

import java.sql.ResultSet;
import java.sql.SQLException;

public class findNumberDao {

    public boolean findNumber(int userId,String picture){

        String sql="select  c_number  from shop where u_id=? and c_pic=?";
        String sql_up="update shop set c_number=? where c_pic=?";

        Object[] pictures={userId,picture};
        boolean b=false;
        int num = 0;
        ResultSet resultSet = DBCPUtils.executeQuery(sql,pictures);

        try {
            while (resultSet.next()){
                num=resultSet.getInt("c_number");
            }
            if(num>0){
                Object[] objects={num+1,picture};
                b=DBCPUtils.executeUpdate(sql_up,objects);
            }else{
                return b;
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            //关闭数据库的方法
            DBCPUtils.closeAll(resultSet, DBCPUtils.pstmt, DBCPUtils.connection);
        }

        return b;
    }
}
